# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
__docformat__ = 'restructuredtext en'
__all__ = []

from ...gamelib import info as gi
from ...packlib import info as cs
from ... import pilelib as stack
from ...piles import larasgame as lstack
from .. import larasgame as lgame

GT, SL = gi.GT, gi.SL
Wrap = stack.StackWrapper


class FatimehsGame(cs.Mughal_Deck, lgame.LarasGame):
    """
    Finish cards on _foundation_ within a turn.

    Layout
      - row [12 over 4 row, no offset]
      - talon [1 E, no offset]
      - waste [1 S, no offset]
      - reserve [18 over 4 row S, no offset]
      - foundation [4 horz, 4 vert NW, no offset]

    :CVariables:
      _row_ : pysollib.stack.Stack
        .. pysollib.stack.OpenStack
        Init all cards per. Build none. Play top.

        Cards deal back on _talon_
          - 1 card when rank is position.
          - 1 card when rank is face card.
          - 2 card when rank is ACE.
          - 5 card after _row_ turn.

      _talon_ : pysollib.stack.Stack
        .. pysollib.stacks.laragame.LarasGame_Talon (self_cards=5,
          max_rounds=3)
        Deal reserve back to its old row rank pile, then deal 1
        card and its new row rank pile on reserve. 2 redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.OpenStack

      _reserve_ : pysollib.stack.Stack
        .. pysollib.stack.OpenStack (max_cards=2)
        Build none. Play top on foundation.

      _foundations_ : pysollib.stack.Stack
        .. pysollib.stack.SS_Foundation * 2
        Build up in rank by same suit. Play top.

      _freecell_ : None

      _hint_ : hint.AbstractHint
        .. hint.defaultHint

    note::
      ⟪highlight_play⟫ disabled. Simplified undo/redo.
    """
    __info__ = dict(id=13003, name='Fatimehʼs Game',
                    category=cs.TYPE_MUGHAL_GANJIFA, game_type=GT.ONE_DECK,
                    decks=1, redeals=2, skill_level=SL.BALANCED,
                    altnames=('Fatimehʼs Game (1 deck)',), version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _talon_ = Wrap(lstack.LarasGame_Talon, self_cards=5, max_rounds=3)
    _foundation_ = (stack.SS_Foundation, ) * 2

    def _suits(self, index):
        return self['suits'][4:] if index else self['suits'][4:]

    def _create_game(self, **kw):
        kw.setdefault('rows', 12)
        return super(FatimehsGame, self)._create_game(**kw)


class RelaxedFatimehsGame(FatimehsGame):
    """
    Finish cards on _foundation_ within a turn.

    Layout
      - row [12 over 4 row, no offset]
      - talon [1 E, no offset]
      - waste [1 S, no offset]
      - reserve [18 over 4 row S, no offset]
      - foundation [4 horz, 4 vert NW, no offset]
      - freecell [1 NE, no offset]

    :CVariables:
      _row_ : pysollib.stack.Stack
        .. pysollib.stack.OpenStack
        Init all cards per. Build none. Play top.

        Cards deal back on _talon_
          - 1 card when rank is position.
          - 1 card when rank is face card.
          - 2 card when rank is ACE.
          - 5 card after _row_ turn.

      _talon_ : pysollib.stack.Stack
        .. pysollib.stacks.laragame.LarasGame_Talon (self_cards=5,
          max_rounds=3)
        Deal reserve back to its old row rank pile, then deal 1
        card and its new row rank pile on reserve. 2 redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.OpenStack

      _reserve_ : pysollib.stack.Stack
        .. pysollib.stack.OpenStack (max_cards=2)
        Build none. Play top on foundation.

      _foundations_ : pysollib.stack.Stack
        .. pysollib.stack.SS_Foundation * 2
        Build up in rank by same suit. Play top.

      _freecell_ : None
        .. pysollib.stacks.laragame.LarasGame_Reserve (max_cards=2)
        Build any from another row. Play top. Max 2 card.

      _hint_ : hint.AbstractHint
        .. hint.defaultHint

    note::
      ⟪highlight_play⟫ disabled. Simplified undo/redo.
    """
    __info__ = dict(id=13015, name='Fatimehʼs Game Relaxed',
                    category=cs.TYPE_MUGHAL_GANJIFA, game_type=GT.ONE_DECK,
                    decks=1, redeals=3, skill_level=SL.BALANCED,
                    altnames=('Fatimehʼs Game (1 deck, Relax)',),
                    version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _freecell_ = Wrap(lstack.LarasGame_Reserve, max_cards=2)


PROVIDES = [FatimehsGame, RelaxedFatimehsGame]